/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package views;

import controllers.Boletos;
import java.awt.Image;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import models.Pelicula;

/**
 *
 * @author kevin_000
 */
public class ComprarBoletos extends javax.swing.JFrame {

    /**
     * Creates new form ComprarBoletos
     */
    ResultSet rs;
    Boletos b;
    ArrayList<Pelicula> funciones;
    Pelicula p;

    public ComprarBoletos() {
        initComponents();
        setSize(880, 500);
        b = new Boletos();
        setLocationRelativeTo(null);
        fillComboBox();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        cmbFunciones = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        lblPoster = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        lblGenero = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        lblSala = new javax.swing.JLabel();
        lblPelicula = new javax.swing.JLabel();
        lblClasificacion = new javax.swing.JLabel();
        lblDuracion = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Proceso de Compra de Boletos");
        getContentPane().setLayout(null);

        jLabel3.setFont(new java.awt.Font("Rockwell", 3, 60)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("LISTA DE Funciones");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(40, 20, 630, 60);

        jLabel2.setFont(new java.awt.Font("Rockwell", 1, 30)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Clasificacion:");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(30, 320, 210, 40);

        cmbFunciones.setFont(new java.awt.Font("Rockwell", 1, 18)); // NOI18N
        cmbFunciones.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cmbFuncionesItemStateChanged(evt);
            }
        });
        getContentPane().add(cmbFunciones);
        cmbFunciones.setBounds(250, 130, 180, 30);

        jLabel4.setFont(new java.awt.Font("Rockwell", 1, 30)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Genero:");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(120, 280, 120, 40);

        jLabel6.setFont(new java.awt.Font("Rockwell", 1, 30)); // NOI18N
        jLabel6.setForeground(new java.awt.Color(255, 255, 255));
        jLabel6.setText("Función:");
        getContentPane().add(jLabel6);
        jLabel6.setBounds(100, 120, 140, 40);

        lblPoster.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/NOIMAGEN1.jpg"))); // NOI18N
        getContentPane().add(lblPoster);
        lblPoster.setBounds(580, 100, 260, 350);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/Boton 7.png"))); // NOI18N
        jButton1.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/Boton 7 Rollover.png"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(260, 400, 140, 50);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/Boton 6.png"))); // NOI18N
        jButton2.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/Boton 6 Rollover.png"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2);
        jButton2.setBounds(90, 400, 140, 50);

        lblGenero.setFont(new java.awt.Font("Century Gothic", 1, 24)); // NOI18N
        lblGenero.setForeground(new java.awt.Color(255, 255, 255));
        getContentPane().add(lblGenero);
        lblGenero.setBounds(250, 290, 300, 36);

        jLabel10.setFont(new java.awt.Font("Rockwell", 1, 30)); // NOI18N
        jLabel10.setForeground(new java.awt.Color(255, 255, 255));
        jLabel10.setText("Duración:");
        getContentPane().add(jLabel10);
        jLabel10.setBounds(90, 240, 150, 40);

        jLabel11.setFont(new java.awt.Font("Rockwell", 1, 30)); // NOI18N
        jLabel11.setForeground(new java.awt.Color(255, 255, 255));
        jLabel11.setText("Pelicula:");
        getContentPane().add(jLabel11);
        jLabel11.setBounds(100, 160, 150, 40);

        jLabel12.setFont(new java.awt.Font("Rockwell", 1, 30)); // NOI18N
        jLabel12.setForeground(new java.awt.Color(255, 255, 255));
        jLabel12.setText("Sala:");
        getContentPane().add(jLabel12);
        jLabel12.setBounds(160, 200, 80, 40);

        lblSala.setFont(new java.awt.Font("Century Gothic", 1, 24)); // NOI18N
        lblSala.setForeground(new java.awt.Color(255, 255, 255));
        getContentPane().add(lblSala);
        lblSala.setBounds(250, 210, 200, 30);

        lblPelicula.setFont(new java.awt.Font("Century Gothic", 1, 24)); // NOI18N
        lblPelicula.setForeground(new java.awt.Color(255, 255, 255));
        getContentPane().add(lblPelicula);
        lblPelicula.setBounds(250, 170, 300, 36);

        lblClasificacion.setFont(new java.awt.Font("Century Gothic", 1, 24)); // NOI18N
        lblClasificacion.setForeground(new java.awt.Color(255, 255, 255));
        getContentPane().add(lblClasificacion);
        lblClasificacion.setBounds(250, 330, 300, 36);

        lblDuracion.setFont(new java.awt.Font("Century Gothic", 1, 24)); // NOI18N
        lblDuracion.setForeground(new java.awt.Color(255, 255, 255));
        getContentPane().add(lblDuracion);
        lblDuracion.setBounds(250, 240, 300, 36);

        jLabel17.setFont(new java.awt.Font("Century Gothic", 1, 24)); // NOI18N
        jLabel17.setForeground(new java.awt.Color(255, 255, 255));
        getContentPane().add(jLabel17);
        jLabel17.setBounds(250, 250, 300, 40);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/deep_abstract-1920x1080.jpg"))); // NOI18N
        getContentPane().add(jLabel1);
        jLabel1.setBounds(-140, -10, 1020, 500);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        ComprarBoletos2 CB2 = new ComprarBoletos2(p, lblSala.getText());
        CB2.setVisible(true);
        this.dispose();

    }//GEN-LAST:event_jButton2ActionPerformed

    private void cmbFuncionesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmbFuncionesItemStateChanged
        try {

            int index;
            rs = b.realizarConsulta("select f.idSala, p.poster from funcion f join pelicula p where p.idPelicula=f.idPelicula and p.titulo like '" + cmbFunciones.getSelectedItem().toString() + "';");
            rs.next();
            index = cmbFunciones.getSelectedIndex();
            p = funciones.get(index);
            lblPelicula.setText(p.getPelicula());
            lblSala.setText(rs.getString("idSala"));
            lblDuracion.setText(p.getDuracion().toString());
            lblGenero.setText(p.getTipoGenero().toString());
            lblClasificacion.setText(p.getClasificacion().toString());
            System.out.println(p.getPoster().toString());
            lblPoster.setIcon(new ImageIcon(p.getPoster()));

        } catch (SQLException ex) {
            Logger.getLogger(ComprarBoletos.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_cmbFuncionesItemStateChanged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ComprarBoletos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ComprarBoletos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ComprarBoletos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ComprarBoletos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ComprarBoletos().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cmbFunciones;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel lblClasificacion;
    private javax.swing.JLabel lblDuracion;
    private javax.swing.JLabel lblGenero;
    private javax.swing.JLabel lblPelicula;
    private javax.swing.JLabel lblPoster;
    private javax.swing.JLabel lblSala;
    // End of variables declaration//GEN-END:variables
    private void fillComboBox() {
        funciones = (ArrayList<Pelicula>) b.getBoletoCompra();
        funciones.stream().forEach((s) -> {
            cmbFunciones.addItem(s.getPelicula());

        });
    }

    private String getPosterUrl(String id) throws SQLException {
        String url;
        rs = b.realizarConsulta("select p.poster from funcion f join pelicula p where p.idPelicula=f.idPelicula and p.titulo like '" + cmbFunciones.getSelectedItem().toString() + "';");
        rs.next();
        url = rs.toString();
        return url;
    }
}
